package approve.action;

import project.active.LogoutActivity;
import model.pojo.Employee;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ApporoveNewActivity extends Activity {
	TextView logout,username,home,welcome, menuApprove,menuNewdocument;
	String database = "admin";
	Bundle language;
	Employee emp= new Employee();
	
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	String lang = "EN";
	ListView list;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_newdocument);
		
		language = getIntent().getExtras().getBundle(getLang());
		
		Intent currentIntent = this.getIntent();
		emp=(Employee) getIntent().getExtras().get("em");
		emp = (Employee)currentIntent.getSerializableExtra("em");
		
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));

		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		
		welcome = (TextView)findViewById(R.id.welcome);
		welcome.setText(language.getString("ac_Welcome"));
		
		home = (TextView)findViewById(R.id.home);
		home.setText(language.getString("ac_home"));
		
		menuApprove = (TextView)findViewById(R.id.menuapproval);
		menuApprove.setText("E-Approval");
		
		menuNewdocument = (TextView)findViewById(R.id.menuNewDocument);
		menuNewdocument.setText("New document");
		
        loadList();
        list.setOnItemClickListener(selectItem);
        
        menuApprove.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ApporoveNewActivity.this, MainEApproval.class);
				intent.putExtra("em",emp);
				intent.putExtra("database", getDatabase());
				intent.putExtra("lang", lang);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
				
			}
		});
        
        home.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ApporoveNewActivity.this,MainList.class);
				
				intent.putExtra("lang", getLang());
				intent.putExtra("database", getDatabase());
				intent.putExtra("em",emp);
				intent.putExtras(getIntent().getExtras());
				startActivity(intent);
			}
		});
	}
	 public String getLang() {
			Bundle extras = getIntent().getExtras();
			if (extras != null) {
				lang = extras.getString("lang");
			}
			return lang;
		}
	    public void loadList(){
	    	ArrayAdapter<String> listType = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listAll(getLang()));
	    	list = (ListView)findViewById(R.id.listTypeDoc);
	    	list.setAdapter(listType);
	    }
	    public String[] listAll(String value){
	    	String[] menu = null;
			if(value.equals("EN")){
				menu = getResources().getStringArray(R.array.newdocument_en);
			}else if(value.equals("KR")){
				menu = getResources().getStringArray(R.array.newdocument_kr);
			}else {
				menu = getResources().getStringArray(R.array.newdocument_vn);
			}
			return menu;
	    }
//	    public ArrayList<String> listAll(){
//	    	ListDocuments call = new ListDocuments();
//	    	ArrayList<String> list = call.getTypeDoc(getLang());
//	    	ArrayList<Typedoc> arr = call.getAllType(getLang());
//	    	for(int i=0;i<arr.size();i++){
//	    		list.add(arr.get(i).getTypeName());
//	    	}
//	    	return call.getTypeDoc(getLang());
//	    }
	    private OnItemClickListener selectItem = new OnItemClickListener() {
	    	public void onItemClick(android.widget.AdapterView<?> arg0, android.view.View arg1, int arg2, long arg3) {
	    		String item = arg0.getItemAtPosition(arg2).toString();
				if(item.equals("Metting Form") || item.equals("íšŒì�˜ì–‘ì‹�") || item.equals("VÄƒn Báº£n Há»™i Há»�p")){
					Intent myIntent = new Intent(ApporoveNewActivity.this,SendDocActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", getDatabase());
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Document Work report") || item.equals("ì¶œìž¥ ì‹ ì²­ì„œ") || item.equals("BÃ¡o cÃ¡o cÃ´ng tÃ¡c")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, WorkReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Daily Report") || item.equals("ì�¼ì�¼ì—…ë¬´ë³´ê³ ì„œ") || item.equals("BÃ¡o cÃ¡o cÃ´ng viá»‡c")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, DailyReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Weekly Report Document") || item.equals("ì£¼ê°„ë³´ê³ ") || item.equals("BÃ¡o cÃ¡o hÃ ng tuáº§n")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, WeeklyReportActivity.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
				else if(item.equals("Purchase Order Form") || item.equals("êµ¬ë§¤ ìš”ì²­ì„œ") || item.equals("Máº«u Mua HÃ ng")){
					Intent myIntent = new Intent(ApporoveNewActivity.this, PurchaseOrderForm.class);
					myIntent.putExtra("lang", getLang());
					myIntent.putExtra("database", database);
					myIntent.putExtras(getIntent().getExtras());
	                startActivityForResult(myIntent, 0);
				}
	    	};
		};
		
		private OnClickListener listenerLogout=new OnClickListener() {

			public void onClick(View v) {
				LoginActivity.flagupdateversion=false;

				Intent i=new Intent(ApporoveNewActivity.this, LogoutActivity.class);
				i.putExtra("database", getDatabase());
				startActivity(i);
			}
		};

}
